// Copyright 2024 The XLS Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// This file serves as an example for the usage of proto_to_dslx tool.
// The Design imports DSLX sources generated by this tool from proto file
// and uses parameters defined there.
import xls.examples.parameterized.parameters;

type DesignParameters = parameters::DesignParameters;

fn add<INPUT_WIDTH: u32, OUTPUT_WIDTH: u32>(x: uN[INPUT_WIDTH], y: uN[INPUT_WIDTH]) -> uN[OUTPUT_WIDTH] {
    let lhs = x as uN[OUTPUT_WIDTH];
    let rhs = y as uN[OUTPUT_WIDTH];
    lhs + rhs
}

fn design_top(x: u64, y: u64) -> u64 {
  let variant: DesignParameters = parameters::PARAMETERS.variant[0];
  let variant_input_width: u32 = variant.input_width;
  let variant_output_width: u32 = variant.output_width;
  let arg_x = x as uN[variant_input_width];
  let arg_y = y as uN[variant_input_width];

  add<variant_input_width, variant_output_width>(arg_x, arg_y) as u64
}
